package com.yl.module.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseEntity<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * ID
	 */
	@TableId(value = "id", type = IdType.AUTO)
	private Integer id;

	/**
	 * 状态
	 */
	@TableLogic(value = "1", delval = "0")
	@TableField(value = "enable", condition= SqlCondition.EQUAL, updateStrategy = FieldStrategy.NOT_NULL)
	private Integer enable;

	@TableField(exist = false)
	private String enableName;


	/**
	 * 创建人
	 */
	@TableField(value = "create_user", fill= FieldFill.INSERT, updateStrategy = FieldStrategy.NOT_EMPTY)
	private Integer createUser;

	/**
	 * 创建时间
	 */
	@TableField(value = "create_time", fill= FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_EMPTY)
	private LocalDateTime createTime;

	/**
	 * 更新人
	 */
	@TableField(value = "update_user", fill= FieldFill.INSERT_UPDATE, updateStrategy = FieldStrategy.NOT_EMPTY)
	private Integer updateUser;

	/**
	 * 更新时间
	 */
	@TableField(value = "update_time", fill= FieldFill.INSERT_UPDATE, updateStrategy = FieldStrategy.NOT_EMPTY)
	private LocalDateTime updateTime;

	/**
	 * version
	 */
	@Version
	@TableField(value = "version", update = "%s+1", fill= FieldFill.INSERT)
	private Long version;

	/**
	 * fastjson 格式化实体bean
	 */
	@Override
	public String toString() {
		return this.getClass().getSimpleName() + "="
				+ JSONObject.toJSONStringWithDateFormat(this, "yyyy-MM-dd HH:mm:ss");
	}

}
